#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int getVal(int n)
    {
        int val = 0;
        while (n)
        {
            int tmp = n % 10;
            val += tmp * tmp;
            n /= 10;
        }
        return val;
    }
    bool isHappy(int n) {
        int fast = getVal(n), slow = n;
        while (fast != slow)
        {
            slow = getVal(slow);
            fast = getVal(getVal(fast));
        }
        return slow == 1;
    }
};